<?php

namespace App\Admin\Controllers;

use App\User;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class UserController extends AdminController
{
    protected $states = [
        'on'  => ['value' => 1, 'text' => '新人', 'color' => 'primary'],
        'off' => ['value' => 0, 'text' => '不是新人', 'color' => 'default'],
    ];
    protected $states1 = [
        'on'  => ['value' => 1, 'text' => '免打搅', 'color' => 'primary'],
        'off' => ['value' => 0, 'text' => '提醒', 'color' => 'default'],
    ];
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '业务员列表';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new User());

        $grid->column('id', __('Id'));
        $grid->column('realname', __('真实姓名'));
        $grid->column('mobile', __('手机号'));
        $grid->column('is_new', __('是否新人'))->switch($this->states);
        $grid->column('is_display','是否免打搅')->switch($this->states1);
        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(User::findOrFail($id));
        $show->field('id', __('Id'));
        $show->field('realname', __('用户名'));
        $show->field('mobile', __('Mobile'));
        $show->field('is_new', __('是否新人'));
        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new User());
        $form->switch('is_new','是否新人')->states($this->states);
        $form->switch('is_display','是否免打搅')->states($this->states1);
        return $form;
    }
}
